var app = getApp()
Page({
  data: {
    height: 0,
    balance:0.00,
    userInfo:{},
    txmoney:50,
    startm:'',
    daym:'',
    erwemapop: false,
    erweima_img: '',
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({ 
          height: res.windowHeight,
          userInfo: app.globalData.userInfo 
        })
      }
    })
    let par = {
      page: 1,
      pagesize: 1
    }
    app.ajax("money_record", par, (data, err) => {
      this.setData({
        balance: data.data.total_fee,
        startm: data.data.start_fee,
        daym: data.data.day_fee
      })
    })
    
  },
  
  inputmoney(e){
    this.setData({
      txmoney:e.detail.value
    })
  },
  submit() {
    app.ajax("check_info", {}, (data, err) => {
      if(data.result == 'error'){
        this.setData({
          erwemapop:true,
          erweima_img: data.data.qrcode
        })
      }else if(data.result == 'success'){
        if (this.data.txmoney!=''){
          let par = {
            fee: this.data.txmoney,
          }
          app.ajax("apply_draw", par, (data, err) => {
            if (data.result == 'success') {
              wx.navigateBack({
              })
            } else {
              wx.showModal({
                title: '提示',
                content: data.message,
              })
            }
          })
        }else{
          wx.showToast({
            title: '提现金额不能是空',
          })
        }
        
      }
    })
    
    
  },

  save() {
    let that = this
    wx.downloadFile({
      url: this.data.erweima_img,
      success: function (res) {
        console.log(res)
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: function (res) {
            wx.showToast({
              title: '保存成功',
            })
            that.setData({
              erwemapop: false
            })
          },
          fail: function (res) {
            console.log(res)
            console.log('fail')
          }
        })
      },
      fail: function () {
        console.log('fail')
      }
    })
  }

})
